package 笔试.吉比特.分值游戏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;

public class Main {
    public static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    public static void main(String[] args) throws IOException {
        int n = nextInt();
        int[][] dp = new int[n + 10][n + 10];
        int[] sum = new int[n + 10];
        for (int i = 1; i <= n; i++) {
            int x = nextInt();
            sum[i] = sum[i - 1] + x;
            dp[i][i] = x;
        }
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j + i - 1 <= n; j++) {
                int tmp = 0;
                for (int k = j; k < j + i - 1; k++)
                    tmp = Math.min(tmp, dp[j][k]);
                for (int k = j + 1; k <= j + i - 1; k++)
                    tmp = Math.min(tmp, dp[k][j + i - 1]);
                dp[j][j + i - 1] = sum[j + i - 1] - sum[j - 1] - tmp;
            }
        }
        int ans = dp[1][n] - (sum[n] - dp[1][n]);
        System.out.println(ans);
    }

    public static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }
}
